package com.bstek.bdf2.core.orm.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;

/**
 * @Title: DataSourceRegisterBeanFactoryPostProcessor
 * @Package: com.bstek.bdf2.core.orm
 * @Description:
 * @Author: zxq
 * @Date: 2024/1/2 - 20:12
 */
public class DataSourceRegisterBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        // 创建父bean的定义
        RootBeanDefinition parentBeanDefinition = new RootBeanDefinition();
        parentBeanDefinition.setBeanClassName("bdf4.dataSourceRegister");
        parentBeanDefinition.getPropertyValues().add("dataSource", beanFactory.getBean("dataSource"));
        parentBeanDefinition.getPropertyValues().add("name", "ds1");
        parentBeanDefinition.getPropertyValues().add("asDefault", true);
        // 注册父bean
//        registry.registerBeanDefinition("dataSourceRegister", parentBeanDefinition);
    }
}
